<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "project".
 *
 * @property int $id
 * @property string|null $name
 * @property int|null $state 0 normal, 1 closed
 * @property string|null $createdAt
 * @property string|null $updatedAt
 */
class Project extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'project';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['state'], 'integer'],
            [['createdAt', 'updatedAt'], 'safe'],
            [['name'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => Yii::t('app', 'Project'),
            'state' => Yii::t('app', 'State'),
            'createdAt' => Yii::t('app', 'Created At'),
            'updatedAt' => Yii::t('app', 'Updated At'),
        ];
    }

    public function getIssues(){
        return $this->hasMany(Issue::class, ['projectId' => 'id']);
    }

    public function getCollectedIssues(){
        return $this->hasMany(Issue::class, ['projectId' => 'id'])->where(['issue.state' => Options::IssueCollected]);
    }

    public function getWorkingIssues(){
        return $this->hasMany(Issue::class, ['projectId' => 'id'])->where(['issue.state' => Options::IssueWorking]);
    }

    public function getFinishedIssues(){
        return $this->hasMany(Issue::class, ['projectId' => 'id'])->where(['issue.state' => Options::IssueFinished]);
    }
}
